package com.loong.data.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonValidate;
import com.loong.data.common.backend.param.GoodsQueryParam;
import com.loong.data.common.backend.param.PageParam;
import com.loong.data.handler.GoodsHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description: 处理后台商品请求的controller
 * @Author: 刘群
 * @Date: 2020/11/12 17:39
 */
@RestController
@RequestMapping("manage/data/goods")
public class GoodsController extends BaseBackendController {

    @Resource
    private GoodsHandler goodsHandler;

    /**
     * 根据商品id查询商品
     * @param param 商品id封装的参数
     * @return 响应的结果
     */
    @PostMapping("findById")
    public Result findGoodsById(@Validated({CommonValidate.class})BaseIdParam param){
        return handlerExecutor.execute(() -> goodsHandler.findGoodsById(param.getId()));
    }

    /**
     * 分页查询es中的商品信息
     * @param goodsParam 商品查询参数
     * @param pageParam 分页参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/goodsList")
    public Result pageQueryGoods(GoodsQueryParam goodsParam, PageParam pageParam){
        return handlerExecutor.execute(() -> goodsHandler.pageQueryGoods(goodsParam,pageParam));
    }
}
